home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / LISTINGS / V_12_05 / ALLISON.ZIP / CURSOR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  1.7 KB  |  107 lines

  1. LISTING 9 - Implements cursor control for the IBM PC
  2. // cursor.cpp
  3.  
  4. #include <dos.h>
  5. #include "cursor.h"
  6. #include "video.h"
  7.  
  8. int Cursor::state = Cursor::init();
  9.  
  10. int Cursor::init()
  11. {
  12.     // Start with a line cursor
  13.     line();
  14.     return LINE;
  15. }
  16.  
  17. void Cursor::set(unsigned start, unsigned stop)
  18. {
  19.     union REGS r;
  20.     
  21.     // Set vertical size of cursor block
  22.     r.h.ah = 1;
  23.     r.h.ch = (unsigned char) start;
  24.     r.h.cl = (unsigned char) stop;
  25.     int86(0x10,&r,&r);
  26. }
  27.  
  28. void Cursor::block()
  29. {
  30.     // Make the cursor a full rectangle
  31.     switch(Video::type())
  32.     {
  33.     case Video::COLOR:
  34.         set(2,7);
  35.         break;
  36.     
  37.     case Video::MONO:
  38.         set(2,13);
  39.         break;
  40.     }
  41.     state = BLOCK;
  42. }
  43.  
  44. void Cursor::line()
  45. {
  46.     // Make the cursor a thin line
  47.     switch(Video::type())
  48.     {
  49.     case Video::COLOR:
  50.         set(6,7);
  51.         break;
  52.     
  53.     case Video::MONO:
  54.         set(12,13);
  55.         break;
  56.     }
  57.     state = LINE;
  58. }
  59.  
  60. void Cursor::flip()
  61. {
  62.     // Toggle between a block and line cursor
  63.     state = !state;
  64.  
  65.     switch(state)
  66.     {
  67.     case LINE:
  68.         line();
  69.         break;
  70.         
  71.     case BLOCK:
  72.         block();
  73.         break;
  74.     }
  75. }
  76.  
  77. void Cursor::off()
  78. {
  79.     // Make the cursor invisible
  80.     set(15,0);
  81. }
  82.  
  83. void Cursor::setpos(int row, int col)
  84. {
  85.    union REGS r;
  86.    
  87.     // Set the cursor position
  88.    r.x.ax = 0x0200;
  89.    r.x.bx = 0;
  90.    r.h.dh = (unsigned char) row;
  91.    r.h.dl = (unsigned char) col;
  92.    int86(0x10,&r,&r);
  93. }
  94.  
  95. void Cursor::getpos(int& row, int& col)
  96. {
  97.    union REGS r;
  98.  
  99.     // Read the cursor position
  100.    r.x.ax = 0x0300;
  101.    r.x.bx = 0;
  102.    int86(0x10,&r,&r);
  103.    row = r.h.dh;
  104.    col = r.h.dl;
  105. }
  106.  
  107.